﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 作 者：曾洋
// 日 期：2012-1-3 16:11:29
// 描 述：联系人信息处理
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using ZX.Web.UI.Controls;
using ZX.CRM.Bussiness;
using ZX.CRM.Library;
using System.Collections.Generic;
using ZX.SYS.Library;
using System.Web.UI.WebControls;
using ZX.BLL;
using ZX.Web.UI.Controls.ControlBind;
//using ZX.Mapping;

namespace ZX.WebApp.Crm.Customer
{
    public partial class EditCrmLinkMan : EditUIPage
    {
        BTCrmCustomer bll = new BTCrmCustomer();
        BDatPhraseDetail bllDetail = new BDatPhraseDetail();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    IList<DatPhraseDetail> listLinkType = bllDetail.GetDatPhraseDetailByClassValue("LinkmanType");
                    DropDownListControl.DropDataSourceBind(this.TypeID, listLinkType, "PhraseText", "PhraseID");
                    IList<DatPhraseDetail> listRelation = bllDetail.GetDatPhraseDetailByClassValue("Relation");
                    DropDownListControl.DropDataSourceBind(this.Relation, listRelation, "PhraseText", "PhraseID"); 
                    ID.Value = Guid.NewGuid().ToString();
                    //自动生成联系人编码
                    Code.Text = ZX.BLL.IDMaker.GetSequenceStr("CUS002");
                    string strId = this.GetStringFromQueryString("id", "");//联系人记录ID
                    string cid = this.GetStringFromQueryString("cid", "");  //客户ID
                    if (cid != "")
                    {
                        CustomId.Value = cid;
                        IList<V_CrmCustomer> vis = bll.GetAllCustomerInfo(new Guid(cid));
                        if (vis != null && vis.Count > 0)
                        {
                            txtCustomId.Value = bll.GetAllCustomerInfo(new Guid(cid))[0].CustomerName;
                        }
                    }
                    //修改给各元素赋值
                    if (strId != "" && DataAction != "insert")
                    {

                        CrmLinkMan clm = bll.GetCrmLinkManInfo(new Guid(strId));
                        if (clm != null)
                        {
                            //Using UIMapping replace here!
                            //ZX.Mapping.IMapping mapper = new ZX.Mapping.WebUiEnMapper(Orders, this);
                            //mapper.EN2UI();

                            ID.Value = clm.ID.ToString();
                            Code.Text = clm.Code;
                            Caption.Text = clm.Caption;
                            TypeID.SelectedValue = clm.TypeID.ToString();
                            Sex.SelectedValue = clm.Sex;
                            Nation.Text = clm.Nation;
                            Position.Text = clm.Position;
                            Birthday.Value = (clm.Birthday.ToString("yyyy-MM-dd") == "1900-01-01" || clm.Birthday.ToString("yyyy-MM-dd") == "0001-01-01") ? "" : clm.Birthday.ToString("yyyy-MM-dd");
                            DeptName.Text = clm.DeptName;
                            Homeplace.Text = clm.Homeplace;
                            BirthdayType.SelectedValue = clm.BirthdayType;
                            CustomId.Value = clm.CustomId.ToString();
                            //txtCustomId.Value = txtCustomId.Value == "" ? bll.GetAllCustomerInfo(clm.CustomId)[0].CustomerName : txtCustomId.Value;
                            SchoolUntity.Text = clm.SchoolUntity;
                            Schoolspeciality.Text = clm.Schoolspeciality;
                            LinkManFancy.Text = clm.LinkManFancy;
                            MobileTel.Text = clm.MobileTel;
                            Email.Text = clm.Email;
                            Fax.Text = clm.Fax;
                            Medical.Text = clm.Medical;
                            Religion.Text = clm.Religion;
                            HomeTel.Text = clm.HomeTel;
                            OfficeTel.Text = clm.OfficeTel;
                            Netting.Text = clm.Netting;
                            HoliType.Text = clm.HoliType;
                            Address.Text = clm.Address;
                            Explain.Text = clm.Explain;
                            FereName.Text = clm.FereName;
                            FereNation.Text = clm.FereNation;
                            FereHomeplace.Text = clm.FereHomeplace;
                            FereFancy.Text = clm.FereFancy;
                            FereBirthday.Text = clm.FereBirthday;
                            FereCompany.Text = clm.FereCompany;
                            ChildName.Text = clm.ChildName;
                            ChildBirthday.Text = clm.ChildBirthday;
                            ChildFancy.Text = clm.ChildFancy;
                            ChildCompany.Text = clm.ChildCompany;
                            EXP1.Text = clm.EXP1;  //子女民族
                            EXP2.Text = clm.EXP2;  //子女籍贯
                            EXP3.Value = clm.EXP3; //年
                            EXP4.Value = clm.EXP4; //月
                            Drink.Value = clm.Drink;//日
                            Dish.Text = clm.Dish;
                            AddUser.Value = clm.AddUser.ToString();
                            AddTime.Value = clm.AddTime.ToString();
                            txtWeibo.Text = clm.Weibo;
                            Relation.SelectedValue = clm.Relation.ToString();
                        }
                    }
                }
                catch (Exception)
                {

                    throw;
                }
            }
        }
        public string getId { get { return this.GetStringFromQueryString("id",""); } }
    }
}